package com.easyUploader.entity.vo;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.easyUploader.entity.dao.Bucket;
import com.easyUploader.mapper.BucketMapper;
import com.easyUploader.service.IBucketService;
import com.easyUploader.threadHolder.FileInfoThreadHolder;
import com.easyUploader.threadHolder.UserThreadHolder;
import io.jsonwebtoken.lang.Assert;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author 大忽悠
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class FileUploadCheckVo {
    @ApiModelProperty("文件md5")
    private String fileMd5;
    @ApiModelProperty("桶名")
    private String bucketName;
    @ApiModelProperty("目录路径")
    private String dirPath;
    @ApiModelProperty("文件名")
    private String fileName;

    public void safeCheck(IBucketService iBucketService) {
        Bucket bucket = iBucketService.getOne(new QueryWrapper<Bucket>().eq("name", bucketName).eq("create_by", UserThreadHolder.get().getId()));
        Assert.notNull(bucket,"bucket不存在");
        FileInfoThreadHolder.setBucketId(bucket.getId());
        FileInfoThreadHolder.setBucketName(bucketName);
    }
}
